package com.servlet.service;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.servlet.dao.ConsumDetailDao;
import com.servlet.vo.ConsumDetail;

public class ConsumDetailService {

	private boolean flag = false;
	
	public boolean add(HttpServletRequest req) throws SQLException{
		
		ConsumDetail obj = new ConsumDetail();
		obj.setCapitalType(Integer.parseInt( req.getParameter("capitalType")));
		obj.setUser_id(Long.parseLong(req.getParameter("uses_id")));
		obj.setEnter_id(Long.parseLong(req.getParameter("enter_id")));
		obj.setConsumptionType_id(Integer.parseInt(req.getParameter("consumptionType_id")));
		obj.setPayment_id(Integer.parseInt(req.getParameter("payment_id")));
		obj.setDetail(req.getParameter("detail"));
		obj.setConsumptionAmount(new BigDecimal(req.getParameter("consumptionAmount")));
		
		flag = new ConsumDetailDao().save(obj);
		
		return flag;
	}
	
	public boolean del(HttpServletRequest req) throws SQLException{
		
		String objId = req.getParameter("objId");
		if(null != objId && !"".equals(objId)){

//			flag = new ConsumDetailDao().delete(Long.parseLong(objId));// 记录不需要删除，错误记录进行冲账
		}
		
		return flag;
	}
	
	public List<ConsumDetail> getList(HttpServletRequest req) throws SQLException{
	
		String currentPage = req.getParameter("currentPage");
		int pageSize = 12;
		int startIndex = 0;
		if(currentPage == null || "".equals(currentPage)){
			currentPage = "1";
		}
		startIndex = (Integer.parseInt(currentPage) - 1) * pageSize;
		
		List<ConsumDetail> objs = new ConsumDetailDao().getList( startIndex, pageSize);
		req.setAttribute("currentPage", currentPage);
		return objs;
	}
	
	
}
